package ar.republicagroup.gestion.view;

import ar.republicagroup.gestion.entities.CuentaBanco;
import ar.republicagroup.gestion.services.ChequeServices;
import ar.republicagroup.gestion.services.CuentaBancoServices;
import ar.republicagroup.gestion.util.AppSession;
import ar.republicagroup.gestion.util.SpringUtils;
import ar.republicagroup.gestion.util.TableColumnAdjuster;
import ar.republicagroup.gestion.util.UserSession;
import ar.republicagroup.gestion.util.helpers.Formato;
import ar.republicagroup.gestion.util.helpers.UserInterfaceHelper;
import ar.republicagroup.gestion.util.messages.UIMessages;
import java.awt.HeadlessException;
import java.awt.print.PrinterException;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import org.apache.log4j.Logger;

public class frmMain extends javax.swing.JFrame {
   /* Services */
   ChequeServices chequeServices = (ChequeServices)SpringUtils.getBean("chequeServices");
   CuentaBancoServices cuentaBancoServices = (CuentaBancoServices)SpringUtils.getBean("cuentaBancoServices");

   /* Logging */
   private static Logger log = Logger.getLogger(frmCheque.class);
   
   Map<String,Object> mapTotalesCapProv = new HashMap<>();
   Map<String,Object> mapClienteLiquidacionImporte = new HashMap();
   Map<CuentaBanco,Object> mapTotalesPorCuenta =new HashMap();
    
    public frmMain() {
        initComponents();
        valoresPorDefecto();
        lblUserName.setText(UserSession.getInstance().getUser_name());
    }

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lblUserName = new javax.swing.JLabel();
        panelLiquidaciones = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        txtTotalLiquidPosibles = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        lblFechaLiquidacion = new javax.swing.JLabel();
        btnImprimirLiquidPosibles = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblLiquidPosibles = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        lblTotalCAP = new javax.swing.JLabel();
        lblTotalVC = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        btnVerGrafica = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblTotalesPorCuenta = new javax.swing.JTable();
        btnImprimirTotPorCuenta = new javax.swing.JButton();
        btnActualizar = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        menuFile = new javax.swing.JMenu();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        menuItemSalir = new javax.swing.JMenuItem();
        menuGestion = new javax.swing.JMenu();
        menuItemCajaDiaria = new javax.swing.JMenuItem();
        menuItemCliente = new javax.swing.JMenuItem();
        menuItemCuentaBanco = new javax.swing.JMenuItem();
        menuItemCheque = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        menuItemLiquidaciones = new javax.swing.JMenuItem();
        menuConfig = new javax.swing.JMenu();
        menuItemCalendario = new javax.swing.JMenuItem();
        menuItemComDeRechazo = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        menuAcercaDe = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("ar/republicagroup/gestion/view/properties/frmMain_es"); // NOI18N
        setTitle(bundle.getString("title")); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel2.setText(bundle.getString("main_title")); // NOI18N

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel3.setText("Usuario:");

        lblUserName.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        lblUserName.setText("user");

        panelLiquidaciones.setBorder(javax.swing.BorderFactory.createTitledBorder("Liquidaciones posibles del día"));

        jLabel4.setText("Total :");

        txtTotalLiquidPosibles.setEditable(false);
        txtTotalLiquidPosibles.setText("0");

        jLabel5.setText("Fecha liquidación:");

        lblFechaLiquidacion.setText("jLabel6");

        btnImprimirLiquidPosibles.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/printer.png"))); // NOI18N
        btnImprimirLiquidPosibles.setText("Imprimir");
        btnImprimirLiquidPosibles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImprimirLiquidPosiblesActionPerformed(evt);
            }
        });

        tblLiquidPosibles.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cliente", "Monto"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblLiquidPosibles.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        jScrollPane3.setViewportView(tblLiquidPosibles);

        javax.swing.GroupLayout panelLiquidacionesLayout = new javax.swing.GroupLayout(panelLiquidaciones);
        panelLiquidaciones.setLayout(panelLiquidacionesLayout);
        panelLiquidacionesLayout.setHorizontalGroup(
            panelLiquidacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLiquidacionesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelLiquidacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnImprimirLiquidPosibles)
                    .addGroup(panelLiquidacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(panelLiquidacionesLayout.createSequentialGroup()
                            .addComponent(jLabel4)
                            .addGap(18, 18, 18)
                            .addComponent(txtTotalLiquidPosibles, javax.swing.GroupLayout.PREFERRED_SIZE, 261, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(panelLiquidacionesLayout.createSequentialGroup()
                            .addComponent(jLabel5)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(lblFechaLiquidacion))))
                .addContainerGap(21, Short.MAX_VALUE))
        );
        panelLiquidacionesLayout.setVerticalGroup(
            panelLiquidacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLiquidacionesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelLiquidacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(lblFechaLiquidacion))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                .addGap(11, 11, 11)
                .addGroup(panelLiquidacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtTotalLiquidPosibles, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnImprimirLiquidPosibles)
                .addGap(12, 12, 12))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Total valores del día"));

        jLabel7.setText("CAP:");

        jLabel8.setText("VC:");

        lblTotalCAP.setText("$0");

        lblTotalVC.setText("$0");

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/stats.png"))); // NOI18N

        btnVerGrafica.setText("Ver gráfica");
        btnVerGrafica.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnVerGraficaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel7))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblTotalCAP)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblTotalVC)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel6)
                        .addGap(49, 49, 49))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnVerGrafica)
                .addGap(22, 22, 22))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(lblTotalCAP))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(lblTotalVC))
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnVerGrafica)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Totales por cuenta"));

        tblTotalesPorCuenta.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Cuenta", "Cheque", "Efectivo"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(tblTotalesPorCuenta);

        btnImprimirTotPorCuenta.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/printer.png"))); // NOI18N
        btnImprimirTotPorCuenta.setText("Imprimir");
        btnImprimirTotPorCuenta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnImprimirTotPorCuentaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap(244, Short.MAX_VALUE)
                        .addComponent(btnImprimirTotPorCuenta))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnImprimirTotPorCuenta)
                .addGap(18, 18, 18))
        );

        btnActualizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/update.png"))); // NOI18N
        btnActualizar.setText("Actualizar");
        btnActualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnActualizarActionPerformed(evt);
            }
        });

        menuFile.setText("Inicio");

        jMenu1.setText("Configurar");

        jMenuItem2.setText("Look and Feel");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        menuFile.add(jMenu1);

        menuItemSalir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        menuItemSalir.setText("Salir");
        menuItemSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemSalirActionPerformed(evt);
            }
        });
        menuFile.add(menuItemSalir);

        jMenuBar1.add(menuFile);

        menuGestion.setText("Gestión");

        menuItemCajaDiaria.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_1, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        menuItemCajaDiaria.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/cash_register.png"))); // NOI18N
        menuItemCajaDiaria.setText("Caja diaria");
        menuItemCajaDiaria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemCajaDiariaActionPerformed(evt);
            }
        });
        menuGestion.add(menuItemCajaDiaria);

        menuItemCliente.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        menuItemCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/customers.png"))); // NOI18N
        menuItemCliente.setText("Clientes");
        menuItemCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemClienteActionPerformed(evt);
            }
        });
        menuGestion.add(menuItemCliente);

        menuItemCuentaBanco.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        menuItemCuentaBanco.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/coins.png"))); // NOI18N
        menuItemCuentaBanco.setText("Cuentas bancarias");
        menuItemCuentaBanco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemCuentaBancoActionPerformed(evt);
            }
        });
        menuGestion.add(menuItemCuentaBanco);

        menuItemCheque.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_3, java.awt.event.InputEvent.CTRL_MASK));
        menuItemCheque.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/cheque.png"))); // NOI18N
        menuItemCheque.setText("Cheques");
        menuItemCheque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemChequeActionPerformed(evt);
            }
        });
        menuGestion.add(menuItemCheque);

        jMenuItem4.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/payment_16.png"))); // NOI18N
        jMenuItem4.setText("Depósitos en efectivo");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        menuGestion.add(jMenuItem4);

        menuItemLiquidaciones.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_4, java.awt.event.InputEvent.CTRL_MASK));
        menuItemLiquidaciones.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/cash_register.png"))); // NOI18N
        menuItemLiquidaciones.setText("Liquidaciones");
        menuItemLiquidaciones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemLiquidacionesActionPerformed(evt);
            }
        });
        menuGestion.add(menuItemLiquidaciones);

        jMenuBar1.add(menuGestion);

        menuConfig.setText("Configurar");

        menuItemCalendario.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/calendar3.png"))); // NOI18N
        menuItemCalendario.setText("Calendario");
        menuItemCalendario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemCalendarioActionPerformed(evt);
            }
        });
        menuConfig.add(menuItemCalendario);

        menuItemComDeRechazo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/taxes_coin.png"))); // NOI18N
        menuItemComDeRechazo.setText("Comisiones de rechazo");
        menuItemComDeRechazo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuItemComDeRechazoActionPerformed(evt);
            }
        });
        menuConfig.add(menuItemComDeRechazo);

        jMenuBar1.add(menuConfig);

        jMenu2.setText("Reportes");

        jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/payment_icon.png"))); // NOI18N
        jMenuItem3.setText("Cheques liquidados");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem3);

        jMenuItem5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/cash.png"))); // NOI18N
        jMenuItem5.setText("Detalle diario por cuenta");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem5);

        jMenuItem8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/piggy_pink.png"))); // NOI18N
        jMenuItem8.setText("Estado de cuenta por fechas");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem8);

        jMenuItem7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ar/republicagroup/gestion/view/images/payment_next.png"))); // NOI18N
        jMenuItem7.setText("Próxima liquidación");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem7);

        jMenuBar1.add(jMenu2);

        menuAcercaDe.setText("Acerca de");

        jMenuItem1.setText("El gurú dice...");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        menuAcercaDe.add(jMenuItem1);

        jMenuBar1.add(menuAcercaDe);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(61, 61, 61)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblUserName)
                        .addGap(190, 190, 190)
                        .addComponent(jLabel2))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(panelLiquidaciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(btnActualizar)
                                .addGap(10, 10, 10)))))
                .addGap(0, 85, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblUserName)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2))
                .addGap(25, 25, 25)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(32, 32, 32)
                        .addComponent(btnActualizar))
                    .addComponent(panelLiquidaciones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(56, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void menuItemClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemClienteActionPerformed
        frmCliente  formulario = new frmCliente();
        formulario.setLocationRelativeTo(this);
        formulario.setVisible(true);
    }//GEN-LAST:event_menuItemClienteActionPerformed

    private void menuItemCuentaBancoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemCuentaBancoActionPerformed
        frmCuentaBanco formulario = new frmCuentaBanco();
        formulario.setLocationRelativeTo(this);
        formulario.setVisible(true);
    }//GEN-LAST:event_menuItemCuentaBancoActionPerformed

    private void menuItemChequeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemChequeActionPerformed
        frmCheque formulario = new frmCheque();
        formulario.setLocationRelativeTo(this);
        formulario.setVisible(true);
    }//GEN-LAST:event_menuItemChequeActionPerformed

    private void menuItemLiquidacionesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemLiquidacionesActionPerformed
       frmLiquidacion formulario = frmLiquidacion.getInstance();
       formulario.setClientesToLiquid(mapClienteLiquidacionImporte.keySet());
       formulario.setLocationRelativeTo(this);
       formulario.setVisible(true);
       formulario.requestFocus();
    }//GEN-LAST:event_menuItemLiquidacionesActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        ChangeLF frmChange = new ChangeLF();
        UserInterfaceHelper.centreWindow(frmChange);
        frmChange.setVisible(true);   
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        frmReporteLiquidacion formulario = new frmReporteLiquidacion(this, false);
        formulario.setLocationRelativeTo(this);
        formulario.setVisible(true);
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void menuItemCalendarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemCalendarioActionPerformed
       if(UserSession.getInstance().getPerfil_id() == UserSession.ADMINISTRADOR){ 
            frmCalendario formulario = new frmCalendario(this, true);
            formulario.setLocationRelativeTo(this);
            formulario.setVisible(true);
       } else {
           JOptionPane.showMessageDialog(this, UIMessages.getInfoMessage("adminLevelRequired"), UIMessages.getInfoMessage("defaultInfoTitle"), JOptionPane.INFORMATION_MESSAGE);
       }
    }//GEN-LAST:event_menuItemCalendarioActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        frmAcercaDe formulario = new frmAcercaDe();
        formulario.setLocationRelativeTo(this);
        formulario.setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void btnActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActualizarActionPerformed
        mostrarTotalesDeCapProv();
        mostrarTotalesPorCuenta();
        mostrarTotalesLiquidacionesPosibles();
    }//GEN-LAST:event_btnActualizarActionPerformed

    private void menuItemComDeRechazoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemComDeRechazoActionPerformed
        if(UserSession.getInstance().getPerfil_id() == UserSession.ADMINISTRADOR){
            modalPanelGestionRechazos formulario = new modalPanelGestionRechazos(this, true);
            formulario.setLocationRelativeTo(this);
            formulario.setVisible(true);
        }else {
            JOptionPane.showMessageDialog(this, UIMessages.getInfoMessage("adminLevelRequired"), UIMessages.getInfoMessage("defaultInfoTitle"), JOptionPane.INFORMATION_MESSAGE);
        }
        
    }//GEN-LAST:event_menuItemComDeRechazoActionPerformed

    private void menuItemSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemSalirActionPerformed
       dispose();
    }//GEN-LAST:event_menuItemSalirActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        frmReporteTotalesPorCuenta formulario = new frmReporteTotalesPorCuenta();
        formulario.setLocationRelativeTo(this);
        formulario.setVisible(true);
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void btnImprimirTotPorCuentaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImprimirTotPorCuentaActionPerformed
        try {
            MessageFormat header = new MessageFormat(UIMessages.getInfoMessage("totalesPorCuenta_title"),new Locale("es","ES"));
            boolean imprimio = tblTotalesPorCuenta.print(JTable.PrintMode.NORMAL, header, null, true, null, true);
        
            if(imprimio){
                log.info("Imprimió reporte de Totales por cuenta...");
            }
        } catch (PrinterException ex) {
            log.error("Error al imprimir...",ex);
        } catch (HeadlessException ex) {
            log.error("Sin encabezado ...",ex);
        }
    }//GEN-LAST:event_btnImprimirTotPorCuentaActionPerformed

    private void btnImprimirLiquidPosiblesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImprimirLiquidPosiblesActionPerformed
       
        //saldoClientes_title
        
        try {
            MessageFormat header = new MessageFormat(UIMessages.getInfoMessage("liquidacionesPosibles_title")+" "+Formato.fechaDDMMYY(new Date()),new Locale("es","ES"));
            boolean imprimio = tblLiquidPosibles.print(JTable.PrintMode.NORMAL, header, null, true, null, true);
                if(imprimio){
                    log.info("Imprimió reporte de Liquidaciones posibles...");
                }
            } catch (PrinterException ex) {
                log.error("Error al imprimir...",ex);
                log.error(ex.getMessage());
            } catch (HeadlessException ex) {
                log.error(ex.getMessage());
                log.error("Sin encabezado ...",ex);
            }
    }//GEN-LAST:event_btnImprimirLiquidPosiblesActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        frmReporteProxLiquidacion formulario = new frmReporteProxLiquidacion(this, true);
        formulario.setLocationRelativeTo(this);
        formulario.setVisible(true);
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        log.info("Cerrando sesión de usuario "+UserSession.getInstance().getUser_name()+"("+UserSession.getInstance().getUser_id()+")");
        System.exit(0);
    }//GEN-LAST:event_formWindowClosed

    private void btnVerGraficaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVerGraficaActionPerformed
         PieChart1 demo = new PieChart1(UIMessages.getInfoMessage("graphPieChart1"));
         demo.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
         demo.pack();
         UserInterfaceHelper.centreWindow(demo);
         //RefineryUtilities.centerFrameOnScreen(demo);
         demo.setVisible(true);
    }//GEN-LAST:event_btnVerGraficaActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
       frmDepositoEfectivo formulario = frmDepositoEfectivo.getInstance();
       formulario.setVisible(true);
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        UserInterfaceHelper.centreWindow(this);
        
        List<Integer> idUsersCaja = new ArrayList<>();
        idUsersCaja.add(8);
        idUsersCaja.add(9);
        idUsersCaja.add(10);
        
        if(! idUsersCaja.contains( UserSession.getInstance().getUser_id() )){
            menuItemCajaDiaria.setEnabled(Boolean.FALSE);
        }

    }//GEN-LAST:event_formWindowOpened

    private void menuItemCajaDiariaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuItemCajaDiariaActionPerformed
        FrmCajaDiaria formulario = FrmCajaDiaria.getInstance();
        formulario.setVisible(true);
    }//GEN-LAST:event_menuItemCajaDiariaActionPerformed

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        FrmReporteCuentaPorFechas formulario = FrmReporteCuentaPorFechas.getInstance();
        UserInterfaceHelper.centreWindow(formulario);
        formulario.setVisible(true);    
    }//GEN-LAST:event_jMenuItem8ActionPerformed

   
    private void valoresPorDefecto(){
        UserInterfaceHelper.setJFrameIconImage(this);
        mostrarTotalesDeCapProv();
        mostrarTotalesLiquidacionesPosibles();
        mostrarTotalesPorCuenta();
    }
    
    private void mostrarTotalesDeCapProv(){
        mapTotalesCapProv = chequeServices.getTotalesProvCap();
        
        if(mapTotalesCapProv.size() > 0){
           try{
                       lblTotalVC.setText("$"+Formato.decimalComaMiles(Double.parseDouble(mapTotalesCapProv.get(ChequeServices.ORIGEN_VC).toString())));
              }catch(Exception ex){
                        log.info("No hay cargados cheques VC");
              }
                    
           try{
                        lblTotalCAP.setText("$"+Formato.decimalComaMiles(Double.parseDouble(mapTotalesCapProv.get(ChequeServices.ORIGEN_CAP_BSAS).toString())));
              }catch(Exception ex){
                        log.info("No hay cargados cheques CAP");
              }
        } else {
                   lblTotalVC.setText("0");
                   lblTotalCAP.setText("0");
        }
       
    }
    
    private void mostrarTotalesPorCuenta(){
        mapTotalesPorCuenta = cuentaBancoServices.getTotalesPorCuenta();
        cargarTablaTotalesPorCuenta(mapTotalesPorCuenta);
    }
  
    private void mostrarTotalesLiquidacionesPosibles(){
        mapClienteLiquidacionImporte = chequeServices.getLiquidacionesPosiblesPorCadaCliente(AppSession.getFechaDeLiquidacion());
        cargarTablaLiquidPosibles(mapClienteLiquidacionImporte);
        lblFechaLiquidacion.setText(Formato.cambiarFechaAFormatoLocal(AppSession.getFechaDeLiquidacion().getTime()));
    }
    
    
    
    private void cargarTablaLiquidPosibles(Map<String,Object> mapita){
        double totalLiquidacionesPosiblesDelDia = 0;
        DefaultTableModel model     = (DefaultTableModel) tblLiquidPosibles.getModel();
        model.getDataVector().clear();
        
        for (Map.Entry<String, Object> entry : mapita.entrySet()) 
        { 
            model.addRow(new Object[]{entry.getKey(),Formato.decimalComaMilesConSigno(Double.parseDouble(entry.getValue().toString()))});
            totalLiquidacionesPosiblesDelDia += Double.parseDouble(entry.getValue().toString());
        }
        
        /*Total*/
        if(model.getRowCount()>0){
          model.addRow(new Object[]{"Total",Formato.decimalComaMilesConSigno((totalLiquidacionesPosiblesDelDia))});
        }
        
        TableColumnAdjuster tca = new TableColumnAdjuster(tblLiquidPosibles);
        tca.adjustColumns();
        tblLiquidPosibles.setModel(model);
        tblLiquidPosibles.repaint();
        txtTotalLiquidPosibles.setText(Formato.decimalComaMilesConSigno(totalLiquidacionesPosiblesDelDia));
    }
    
    
    private void cargarTablaTotalesPorCuenta(Map<CuentaBanco,Object> mapita){
        double totalesPorCuenta = 0;
        DefaultTableModel model     = (DefaultTableModel) tblTotalesPorCuenta.getModel();
        model.getDataVector().clear();
        
        for (Map.Entry<CuentaBanco, Object> entry : mapita.entrySet()) 
        { 
            model.addRow(new Object[]{entry.getKey(),Formato.decimalComaMilesConSigno(((BigDecimal)entry.getValue()).doubleValue())});
            totalesPorCuenta += ((BigDecimal)entry.getValue()).doubleValue();
            
        }
        
        /*Total*/
        model.addRow(new Object[]{"Total",Formato.decimalComaMilesConSigno((totalesPorCuenta))});
        
        TableColumnAdjuster tca = new TableColumnAdjuster(tblTotalesPorCuenta);
        tca.adjustColumns();
        tblTotalesPorCuenta.setModel(model);
        tblTotalesPorCuenta.repaint();
    }
    
    
    

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmMain().setVisible(true);
            }
        });
        
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    protected static javax.swing.JButton btnActualizar;
    private javax.swing.JButton btnImprimirLiquidPosibles;
    private javax.swing.JButton btnImprimirTotPorCuenta;
    private javax.swing.JButton btnVerGrafica;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JLabel lblFechaLiquidacion;
    private javax.swing.JLabel lblTotalCAP;
    private javax.swing.JLabel lblTotalVC;
    private javax.swing.JLabel lblUserName;
    private javax.swing.JMenu menuAcercaDe;
    private javax.swing.JMenu menuConfig;
    private javax.swing.JMenu menuFile;
    private javax.swing.JMenu menuGestion;
    private javax.swing.JMenuItem menuItemCajaDiaria;
    private javax.swing.JMenuItem menuItemCalendario;
    private javax.swing.JMenuItem menuItemCheque;
    private javax.swing.JMenuItem menuItemCliente;
    private javax.swing.JMenuItem menuItemComDeRechazo;
    private javax.swing.JMenuItem menuItemCuentaBanco;
    private javax.swing.JMenuItem menuItemLiquidaciones;
    private javax.swing.JMenuItem menuItemSalir;
    private javax.swing.JPanel panelLiquidaciones;
    private javax.swing.JTable tblLiquidPosibles;
    private javax.swing.JTable tblTotalesPorCuenta;
    private javax.swing.JTextField txtTotalLiquidPosibles;
    // End of variables declaration//GEN-END:variables
}
